///  author : zhangjiang
///  date : 2023/12/27
///  description :zjLogFile

//是否是release
import 'package:flutter/foundation.dart';

void zjLog(Object message, {StackTrace? stack}) {
  ///release 模式下不打印
  if(kDebugMode){
    if (stack != null) {
      ZJCustomTrace programInfo = ZJCustomTrace(stack);
      print("所在文件: ${programInfo.fileName}, 所在行: ${programInfo.lineNumber}, 打印信息: $message");
    }else{
      print("message:$message");
    }
  }
}

class ZJCustomTrace {
  final StackTrace _trace;

  late String fileName;
  late int lineNumber;
  late int columnNumber;

  ZJCustomTrace(this._trace) {
    _parseTrace();
  }

  void _parseTrace() {
    var traceString = _trace.toString().split("\n")[0];
    var indexOfFileName = traceString.indexOf(RegExp(r'[A-Za-z_]+.dart'));
    var fileInfo = traceString.substring(indexOfFileName);
    var listOfInfos = fileInfo.split(":");
    fileName = listOfInfos[0];
    lineNumber = int.parse(listOfInfos[1]);
    var columnStr = listOfInfos[2];
    columnStr = columnStr.replaceFirst(")", "");
    columnNumber = int.parse(columnStr);
  }
}